var oScorm = pipwerks.SCORM;  // define a SCORM object to interface with PIPWerks code

var nOverallScore = 0;   

// This function initializes the course by connecting to the LMS and retrieving 

// the student's name.

function initCourse()
{
  	var lmsConnected = oScorm.init();

	if( lmsConnected )

	{
            // always set the status to incomplete
		oScorm.set("cmi.lesson_status", "incomplete");
		oScorm.set("cmi.success_status", "unknown");
		oScorm.set("cmi.completion_status", "incomplete");

	}

}

/*
* 
* in the last page, do this:
* 
* <body onload="window.parent.setScore()>
*/

    // Call this function at the very end of the course when the final

    // score has been calculated.

function setScore( nOverallScore )

{

	nOverallScore = nOverallScore * 10;

    // Set the values and status here

        oScorm.set( "cmi.score.min", "0" );

        oScorm.set( "cmi.score.max", "100" );
        oScorm.set( "cmi.score.raw", nOverallScore );
        oScorm.set( "cmi.score.scaled", nOverallScore / 100 );
        oScorm.set( "cmi.completion_status", "completed" );

        

	if( nOverallScore >= 70 )
        oScorm.set( "cmi.success_status", "passed" );
    else
        oScorm.set( "cmi.success_status", "failed" );
}

// This function is called when the window is closed.  It saves and quits the course.

function finishCourse()
{
	oScorm.save();
	oScorm.quit();
}